//
//  JSBaseNavController.swift
//  JS weibo
//
//  Created by Jackie on 16/5/30.
//  Copyright © 2016年 Jackie. All rights reserved.
//

import UIKit

class JSBaseNavController: UINavigationController,UIGestureRecognizerDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = self
    }
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        var backtitle = "返回"
        if childViewControllers.count > 0 {
            if childViewControllers.count == 1 {
                backtitle = childViewControllers.first?.title ?? "返回"
            }
            let back = UIBarButtonItem(imageName: "navigationbar_back_withtext",title: backtitle, target: self, action: #selector(popToFrontVC))
            viewController.navigationItem.leftBarButtonItem = back
        }
        super.pushViewController(viewController, animated: animated)
        print(childViewControllers.count)
    }
    
    @objc private func popToFrontVC() {
        popViewControllerAnimated(true)
    }
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return childViewControllers.count > 1
        
        }
    }
    
    
    
    
    

